package adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.menhoo.toollibrary.common.helper.AndroidFileUtil;
import com.example.menhoo.toollibrary.common.utils.AndroidUtil;
import com.example.menhoo.toollibrary.common.utils.BitmapUtil;
import com.example.menhoo.toollibrary.common.utils.FileUtil;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.db.sqlite.Selector;
import com.lidroid.xutils.util.LogUtils;
import com.zejian.emotionkeyboard.utils.EmotionUtils;
import com.zejian.emotionkeyboard.utils.SpanStringUtils;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import application.AppApplication;
import application.HttpUrlConstant;
import application.UIApplication;
import custom.ScaleImagesActivity;
import menhoo.com.i8officelibrary.R;
import model.DownloadDbModel;
import model.IMFileModel;
import model.IMMessageDBModel;
import model.ImageInfo;

import static application.UIApplication.getDB;

/**
 * Created by yanglei on 17/1/10.
 */
public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ImViewHolder>{
    private LayoutInflater inflater;
    private Context context;
    private List<IMMessageDBModel> list;
    private String Type = "group";
    BitmapUtils bitmapUtils = null;
    public static Date tempTime = null;
    int Minute =3;

    public MessageAdapter(Context context,String IMType){
        this.Type=IMType;
        this.context = context;
        this.inflater = LayoutInflater.from(this.context);
        this.list = new ArrayList<>();
        this.bitmapUtils =new BitmapUtils(context, UIApplication.getAppCachePath(context));
    }
    public MessageAdapter(Context context,String IMType, List<IMMessageDBModel> data){
        this.Type=IMType;
        this.context = context;
        this.inflater = LayoutInflater.from(this.context);
        this.list = data;
        this.bitmapUtils =new BitmapUtils(context, UIApplication.getAppCachePath(context));
    }

    public interface OnItemClickLitener
    {
        void onItemClick(View view, int position);
        void onItemLongClick(View view , int position);
    }
    public interface OnSendAginLitener
    {
        void onSendTextAgin(int position);
        void onSendImageAgin(int position);
    }

    private OnItemClickLitener mOnItemClickLitener;
    private OnSendAginLitener mOnSendAginLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener)
    {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }
    public void setmOnSendAginLitener(OnSendAginLitener mOnSendAginLitener){
        this.mOnSendAginLitener = mOnSendAginLitener;
    }
    public void sort(){
        Collections.sort(this.list, new Comparator<IMMessageDBModel>() {
            @Override
            public int compare(IMMessageDBModel lhs, IMMessageDBModel rhs) {
                return lhs.CreateTime.compareTo(rhs.CreateTime);
            }
        });
    }
    public void add(IMMessageDBModel item){
        LogUtils.e("this.list.size():"+this.list.size());
        this.list.add(item);
        refreshTime();
        sort();
        LogUtils.e("this.list.size() getItemCount:"+getItemCount());
        notifyItemInserted(getItemCount()-1);
    }

    public void add(List<IMMessageDBModel> data){
        int p = getItemCount();
        this.list.addAll(data);
        refreshTime();
        sort();
        notifyItemRangeInserted(p,data.size());
    }
    public void add(int position,List<IMMessageDBModel> data){
        this.list.addAll(position,data);
        refreshTime();
        notifyItemRangeInserted(position,data.size());
    }

    public void refreshTime(){
        int i = 0;
        if(this.list!=null && this.list.size()>0){
            for(IMMessageDBModel item : this.list){
                if(i==0){
                    item.isShowTime=true;
                    tempTime = item.CreateTime;
                }
                else{
                    if(item.CreateTime.getTime()-tempTime.getTime()>1000*60*Minute)
                    {
                        item.isShowTime=true;
                        tempTime = item.CreateTime;
                    }
                    else{
                        item.isShowTime=false;
                    }
                }
                i++;
            }
        }

    }

    public List<IMMessageDBModel> getData(){
        return this.list;
    }

    public IMMessageDBModel getItem(int position){
        return this.list.get(position);
    }
    public IMMessageDBModel getItem(String id){
        for(IMMessageDBModel item : this.list){
            if(item.ID.equalsIgnoreCase(id)){
                return item;
            }
        }
        return null;
    }
    public IMMessageDBModel getItemByUID(String uid){
        for(IMMessageDBModel item : this.list){
            if(item.UID.equalsIgnoreCase(uid)){
                return item;
            }
        }
        return null;
    }
    public int getPositionByUID(String uid){
        int i =0;
        for(IMMessageDBModel item : this.list){
            if(item.UID.equalsIgnoreCase(uid)){
                return i;
            }
            i++;
        }
        return -1;
    }
    public void deleteByUID(String uid){
        for(IMMessageDBModel item : this.list){
            if(item.UID.equalsIgnoreCase(uid)){
                this.list.remove(item);
                return;
            }
        }
    }

    @Override
    public ImViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        if(viewType==ITEM_TYPE.Text.ordinal()){
            view = inflater.inflate(R.layout.im_details_adapter_item_right,parent,false);
        }
        else if(viewType==ITEM_TYPE.TextOther.ordinal()){
            view = inflater.inflate(R.layout.im_details_adapter_item_left,parent,false);
        }
        else if(viewType==ITEM_TYPE.Image.ordinal()){
            view = inflater.inflate(R.layout.im_details_adapter_item_right,parent,false);
        }
        else if(viewType==ITEM_TYPE.ImageOther.ordinal()){
            view = inflater.inflate(R.layout.im_details_adapter_item_left,parent,false);
        }
        else if(viewType==ITEM_TYPE.File.ordinal()){
            view = inflater.inflate(R.layout.im_details_adapter_item_file_right,parent,false);
        }
        else if(viewType==ITEM_TYPE.FileOther.ordinal()){
            view = inflater.inflate(R.layout.im_details_adapter_item_file_left,parent,false);
        }
        else if(viewType==ITEM_TYPE.System.ordinal()){
            view = inflater.inflate(R.layout.im_details_adapter_item_system,parent,false);
        }
        else if(viewType==ITEM_TYPE.UploadImg.ordinal()){
            view = inflater.inflate(R.layout.im_details_adapter_item_right,parent,false);
        }
        else if(viewType==ITEM_TYPE.UploadFile.ordinal()){
            view = inflater.inflate(R.layout.im_details_adapter_item_file_right,parent,false);
        }
        else{
            view = inflater.inflate(R.layout.im_details_adapter_item_right,parent,false);
        }

        ImViewHolder imViewHolder = new ImViewHolder(view,viewType);

        return imViewHolder;
    }


    @Override
    public void onBindViewHolder(final ImViewHolder holder, int position) {
        final IMMessageDBModel item = list.get(position);
        Map<String,String> parm= new HashMap<String,String>();
        parm.put("emplid", item.SenderID);
        String imgUserUrl= HttpUrlConstant.getWebSiteFullUrl(HttpUrlConstant.doShowPhoto, parm);

        if(item.isShowTime)
        {
            try
            {
                holder.textViewTime.setText(item.CreateTimeToString);
                holder.textViewTime.setVisibility(View.VISIBLE);
            }
            catch (Exception e){
                LogUtils.e(e.getMessage()+"");
            }
        }
        else
        {
            holder.textViewTime.setVisibility(View.GONE);
        }

        // 如果设置了回调，则设置点击事件
        if (mOnItemClickLitener != null)
        {
            holder.itemView.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView, pos);
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener()
            {
                @Override
                public boolean onLongClick(View v)
                {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemLongClick(holder.itemView, pos);
                    return false;
                }
            });
        }

        if(item.MessageType.equalsIgnoreCase("Text"))
        {
            if(item.SenderType.equalsIgnoreCase("System")){
                holder.textViewContext.setText(item.DecContext);
            }
            else{
                if(item.SenderID.equalsIgnoreCase(AppApplication.getUser().EmplID)){

                    holder.textViewContext.setText(SpanStringUtils.getEmotionContent(EmotionUtils.EMOTION_CLASSIC_TYPE,context,holder.textViewContext,item.DecContext));

                    //holder.textViewContext.setText(item.DecContext);
                    bitmapUtils.display(holder.imageViewUser,imgUserUrl);
                    holder.linearLayoutPercent.setVisibility(View.GONE);
                    holder.relativeLayoutImage.setVisibility(View.GONE);

                    if(item.SendStatus.equalsIgnoreCase("0")){
                        holder.linearLayoutBtn.setVisibility(View.GONE);
                        holder.progressBar.setVisibility(View.GONE);
                        holder.imgBtnAgin.setVisibility(View.GONE);
                    }
                    else if(item.SendStatus.equalsIgnoreCase("1")){
                        holder.linearLayoutBtn.setVisibility(View.VISIBLE);
                        holder.progressBar.setVisibility(View.VISIBLE);
                        holder.imgBtnAgin.setVisibility(View.GONE);
                    }
                    else if(item.SendStatus.equalsIgnoreCase("2")){
                        holder.linearLayoutBtn.setVisibility(View.VISIBLE);
                        holder.progressBar.setVisibility(View.GONE);
                        holder.imgBtnAgin.setVisibility(View.VISIBLE);

                        holder.imgBtnAgin.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                if(mOnSendAginLitener!=null){
                                    int pos = holder.getLayoutPosition();
                                    mOnSendAginLitener.onSendTextAgin(pos);
                                }
                            }
                        });
                    }

                }
                else{
                    if(Type.toLowerCase().equalsIgnoreCase("group")){
                        holder.textViewName.setVisibility(View.VISIBLE);
                        holder.textViewName.setText(item.SenderName);
                    }
                    else{
                        holder.textViewName.setVisibility(View.GONE);
                    }

                    //holder.textViewContext.setText( item.DecContext);
                    holder.textViewContext.setText(SpanStringUtils.getEmotionContent(EmotionUtils.EMOTION_CLASSIC_TYPE,context,holder.textViewContext,item.DecContext));

                    bitmapUtils.display(holder.imageViewUser,imgUserUrl);
                    holder.relativeLayoutImage.setVisibility(View.GONE);
                }
            }


        }
        else if(item.MessageType.equalsIgnoreCase("File")){
            final IMFileModel fileModel = item.getFileInfo();
            if(fileModel!=null){
                if(BitmapUtil.isImage(fileModel.Ext))
                {
                    Map<String,String> parmImg= new HashMap<String,String>();
                    parmImg.put("attid", fileModel.ID);
                    parmImg.put("fileName", URLEncoder.encode(fileModel.Name));
                    parmImg.put("width", "300");
                    parmImg.put("imgLevel", "90");
                    final String imgUrl=HttpUrlConstant.getWebSiteFullUrl(HttpUrlConstant.Download, parmImg);

                    Map<String,String> parmImg2= new HashMap<String,String>();
                    parmImg2.put("attid", fileModel.ID);
                    parmImg2.put("fileName", URLEncoder.encode(fileModel.Name));
                    final String imgUrl2= HttpUrlConstant.getWebSiteFullUrl(HttpUrlConstant.Download, parmImg2);

                    holder.imageViewContext.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent it = new Intent(context, ScaleImagesActivity.class);// 创建Intent对象
                            it.putExtra("imageInfo", new ImageInfo(fileModel.Name,imgUrl2));
                            context.startActivity(it);
                        }
                    });

                    ViewGroup.LayoutParams params = holder.relativeLayoutImage.getLayoutParams();
                    params.width=AndroidUtil.dp2px(context,200);
                    params.height=AndroidUtil.dp2px(context,266);
                    try{
                        params.width = AndroidUtil.dp2px(context,fileModel.Info.Width/3*2);
                        params.height= AndroidUtil.dp2px(context,fileModel.Info.Height/3*2);
                    }
                    catch (Exception ex){}

                    holder.relativeLayoutImage.setLayoutParams(params);

                    if(item.SenderID.equalsIgnoreCase(AppApplication.getUser().EmplID)){
                        holder.textViewContext.setVisibility(View.GONE);
                        bitmapUtils.display(holder.imageViewUser,imgUserUrl);
                        holder.linearLayoutPercent.setVisibility(View.GONE);
                        holder.relativeLayoutImage.setVisibility(View.VISIBLE);
                        holder.linearLayoutBtn.setVisibility(View.GONE);
                        bitmapUtils.display(holder.imageViewContext,imgUrl);
                    }
                    else{
                        if(Type.toLowerCase().equalsIgnoreCase("group")){
                            holder.textViewName.setVisibility(View.VISIBLE);
                            holder.textViewName.setText(item.SenderName);
                        }
                        else{
                            holder.textViewName.setVisibility(View.GONE);
                        }
                        holder.textViewContext.setVisibility(View.GONE);
                        bitmapUtils.display(holder.imageViewUser,imgUserUrl);
                        holder.relativeLayoutImage.setVisibility(View.VISIBLE);
                        bitmapUtils.display(holder.imageViewContext,imgUrl);
                    }

                }
                else
                {
                    if(item.SenderID.equalsIgnoreCase(AppApplication.getUser().EmplID))
                    {
                        bitmapUtils.display(holder.imageViewUser,imgUserUrl);
                        holder.imageViewFile.setImageResource(AndroidFileUtil.getFileIconRIDFileExt(fileModel.Ext));
                        holder.textViewFileName.setText(fileModel.Name);
                        holder.textViewFileSize.setText(FileUtil.formatFileSizeToString(fileModel.Size));
                        holder.progressBarDownload.setVisibility(View.GONE);
                        holder.linearLayoutBtn.setVisibility(View.GONE);
                    }
                    else
                    {
                        if(Type.toLowerCase().equalsIgnoreCase("group"))
                        {
                            holder.textViewName.setVisibility(View.VISIBLE);
                            holder.textViewName.setText(item.SenderName);
                        }
                        else
                        {
                            holder.textViewName.setVisibility(View.GONE);
                        }
                        bitmapUtils.display(holder.imageViewUser,imgUserUrl);
                        holder.imageViewFile.setImageResource(AndroidFileUtil.getFileIconRIDFileExt(fileModel.Ext));
                        holder.textViewFileName.setText(fileModel.Name);
                        holder.textViewFileSize.setText(FileUtil.formatFileSizeToString(fileModel.Size));
                        holder.progressBarDownload.setVisibility(View.GONE);
                    }
                    if(item.Progress==0 || item.Progress==100)
                    {
                        holder.progressBarDownload.setVisibility(View.GONE);
                        //看看这个文件是否下载过
                        DownloadDbModel downloadDbModel;
                        try {
                            downloadDbModel = getDB().findFirst(Selector.from(DownloadDbModel.class).where("tag", "=", item.UID));
                            if (downloadDbModel != null) {
                                if (downloadDbModel.isComplete) {
                                    holder.textViewFileStatus.setText("打开");
                                } else {
                                    holder.textViewFileStatus.setText("继续下载");
                                }

                            }
                            else{
                                holder.textViewFileStatus.setText("下载");
                            }
                        } catch (Exception e) {
                            LogUtils.e(e.getMessage() + "");
                        }
                    }
                    else
                    {
                        holder.progressBarDownload.setVisibility(View.VISIBLE);
                        holder.progressBarDownload.setMax(100);
                        holder.progressBarDownload.setProgress((int)item.Progress);
                        holder.textViewFileStatus.setText("下载中");
                    }



                }
            }
            else{
                super.getItemViewType(position);
            }
        }
        else if(item.MessageType.equalsIgnoreCase("UploadImg")){

            ViewGroup.LayoutParams params = holder.relativeLayoutImage.getLayoutParams();

            params.width = AndroidUtil.dp2px(context,200);
            params.height= AndroidUtil.dp2px(context,266);
            holder.relativeLayoutImage.setLayoutParams(params);

            holder.textViewContext.setVisibility(View.GONE);


            holder.relativeLayoutImage.setVisibility(View.VISIBLE);
            holder.linearLayoutBtn.setVisibility(View.GONE);
            if(item.Progress==0 || holder.imageViewContext.getDrawable()==null){
                bitmapUtils.display(holder.imageViewUser,imgUserUrl);
                bitmapUtils.display(holder.imageViewContext,"file://"+item.DecContext);
            }
            if(item.SendStatus.equalsIgnoreCase("1")){
                holder.linearLayoutPercent.setVisibility(View.VISIBLE);
                if(item.Progress==100){
                    holder.linearLayoutPercent.setVisibility(View.GONE);
                    holder.imageViewContext.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent it = new Intent(context, ScaleImagesActivity.class);// 创建Intent对象
                            it.putExtra("imageInfo", new ImageInfo("","file://"+item.DecContext));
                            context.startActivity(it);
                        }
                    });
                }
                else{
                    holder.textViewPercent.setText(item.Progress+"%");
                }
            }
            else if(item.SendStatus.equalsIgnoreCase("2")){
                holder.linearLayoutPercent.setVisibility(View.GONE);
                holder.linearLayoutBtn.setVisibility(View.VISIBLE);
                holder.imgBtnAgin.setVisibility(View.VISIBLE);
                holder.progressBar.setVisibility(View.GONE);
                holder.imgBtnAgin.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(mOnSendAginLitener!=null){
                            int pos = holder.getLayoutPosition();
                            mOnSendAginLitener.onSendImageAgin(pos);
                        }
                    }
                });
            }


        }
        else if(item.MessageType.equalsIgnoreCase("UploadFile")){
            if(item.Progress==0 || holder.imageViewUser.getDrawable()==null){
                bitmapUtils.display(holder.imageViewUser,imgUserUrl);
            }

            holder.imageViewFile.setImageResource(AndroidFileUtil.getFileIconRIDFileExt(AndroidFileUtil.getSuffix(item.DecContext)));
            holder.textViewFileName.setText(item.SenderName);
            holder.textViewFileSize.setText(FileUtil.formatFileSizeToString(Long.parseLong(item.Context)));
            holder.progressBarDownload.setVisibility(View.GONE);
            holder.linearLayoutBtn.setVisibility(View.GONE);
            holder.textViewFileStatus.setText("上传");

            if(item.SendStatus.equalsIgnoreCase("1")){
                holder.progressBarDownload.setVisibility(View.VISIBLE);
                if(item.Progress==100){

                    holder.progressBarDownload.setVisibility(View.GONE);
                    holder.textViewFileStatus.setText("上传完成");
                    holder.linearLayoutContent.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //打开文件
                            String path = item.DecContext;
                            context.startActivity(AndroidFileUtil.openFile(path));
                        }
                    });

                }
                else{

                    holder.progressBarDownload.setMax(100);
                    holder.progressBarDownload.setProgress((int)item.Progress);
                    holder.textViewFileStatus.setText("上传中");
                }
            }
            else if(item.SendStatus.equalsIgnoreCase("2")){
                holder.linearLayoutBtn.setVisibility(View.VISIBLE);
                holder.imgBtnAgin.setVisibility(View.VISIBLE);
                holder.progressBar.setVisibility(View.GONE);
                holder.textViewFileStatus.setText("上传失败");
                holder.imgBtnAgin.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(mOnSendAginLitener!=null){
                            int pos = holder.getLayoutPosition();
                            mOnSendAginLitener.onSendImageAgin(pos);
                        }
                    }
                });
            }
        }
    }

    @Override
    public int getItemCount() {
        return this.list.size();
    }

    @Override
    public int getItemViewType(int position) {
        IMMessageDBModel item = list.get(position);

        if(item.MessageType.equalsIgnoreCase("Text"))
        {
            if(item.SenderType.equalsIgnoreCase("System")){
                return ITEM_TYPE.System.ordinal();
            }
            else{
                if(item.SenderID.equalsIgnoreCase(AppApplication.getUser().EmplID)){
                    return ITEM_TYPE.Text.ordinal();
                }
                else{
                    return ITEM_TYPE.TextOther.ordinal();
                }
            }
        }
        else if(item.MessageType.equalsIgnoreCase("File")){
            IMFileModel fileModel = item.getFileInfo();
            if(fileModel!=null){
                if(BitmapUtil.isImage(fileModel.Ext)){
                    if(item.SenderID.equalsIgnoreCase(AppApplication.getUser().EmplID)){
                        return ITEM_TYPE.Image.ordinal();
                    }
                    else{
                        return ITEM_TYPE.ImageOther.ordinal();
                    }

                }
                else
                {
                    if(item.SenderID.equalsIgnoreCase(AppApplication.getUser().EmplID)){
                        return ITEM_TYPE.File.ordinal();
                    }
                    else{
                        return ITEM_TYPE.FileOther.ordinal();
                    }

                }
            }
            else{
                super.getItemViewType(position);
            }
        }
        else if(item.MessageType.equalsIgnoreCase("UploadImg")){
            return ITEM_TYPE.UploadImg.ordinal();
        }
        else if(item.MessageType.equalsIgnoreCase("UploadFile")){
            return ITEM_TYPE.UploadFile.ordinal();
        }
        else if(item.MessageType.equalsIgnoreCase("Download")){
            return ITEM_TYPE.Download.ordinal();
        }
        else{
            LogUtils.e("position:"+position);
        }
        return super.getItemViewType(position);
    }

    class ImViewHolder extends RecyclerView.ViewHolder{
        //Text
        public TextView textViewContext,textViewPercent,textViewName,textViewTime;
        public RelativeLayout relativeLayoutImage;
        public ImageView imageViewContext,imageViewUser;
        public LinearLayout linearLayoutPercent,linearLayoutBtn;
        public ImageButton imgBtnAgin;
        public ProgressBar progressBar;

        //File
        public ImageView imageViewFile;
        public TextView textViewFileName,textViewFileSize,textViewFileStatus;
        public ProgressBar progressBarDownload;
        public LinearLayout linearLayoutContent;


        public ImViewHolder(View itemView) {
            super(itemView);
        }
        public ImViewHolder(View itemView,int viewType) {
            super(itemView);
            if(viewType==ITEM_TYPE.Text.ordinal()){
                textViewTime = (TextView) itemView.findViewById(R.id.textViewTime);
                textViewContext = (TextView) itemView.findViewById(R.id.textViewContext);
                textViewPercent = (TextView) itemView.findViewById(R.id.textViewPercent);
                relativeLayoutImage = (RelativeLayout) itemView.findViewById(R.id.relativeLayoutImage);
                imageViewContext = (ImageView) itemView.findViewById(R.id.imageViewContext);
                imageViewUser = (ImageView) itemView.findViewById(R.id.imageViewUser);
                linearLayoutPercent = (LinearLayout) itemView.findViewById(R.id.linearLayoutPercent);
                linearLayoutBtn = (LinearLayout) itemView.findViewById(R.id.linearLayoutBtn);
                imgBtnAgin = (ImageButton) itemView.findViewById(R.id.imgBtnAgin);
                progressBar = (ProgressBar) itemView.findViewById(R.id.progressBar);
            }
            else if(viewType==ITEM_TYPE.TextOther.ordinal()){
                textViewTime = (TextView) itemView.findViewById(R.id.textViewTime);
                textViewName = (TextView) itemView.findViewById(R.id.textViewName);
                textViewContext = (TextView) itemView.findViewById(R.id.textViewContext);
                relativeLayoutImage = (RelativeLayout) itemView.findViewById(R.id.relativeLayoutImage);
                imageViewUser = (ImageView) itemView.findViewById(R.id.imageViewUser);
                imageViewContext = (ImageView) itemView.findViewById(R.id.imageViewContext);
            }
            else if(viewType==ITEM_TYPE.Image.ordinal()){
                textViewTime = (TextView) itemView.findViewById(R.id.textViewTime);
                textViewContext = (TextView) itemView.findViewById(R.id.textViewContext);
                textViewPercent = (TextView) itemView.findViewById(R.id.textViewPercent);
                relativeLayoutImage = (RelativeLayout) itemView.findViewById(R.id.relativeLayoutImage);
                imageViewContext = (ImageView) itemView.findViewById(R.id.imageViewContext);
                imageViewUser = (ImageView) itemView.findViewById(R.id.imageViewUser);
                linearLayoutPercent = (LinearLayout) itemView.findViewById(R.id.linearLayoutPercent);
                linearLayoutBtn = (LinearLayout) itemView.findViewById(R.id.linearLayoutBtn);
                imgBtnAgin = (ImageButton) itemView.findViewById(R.id.imgBtnAgin);
                progressBar = (ProgressBar) itemView.findViewById(R.id.progressBar);
            }
            else if(viewType==ITEM_TYPE.ImageOther.ordinal()){
                textViewTime = (TextView) itemView.findViewById(R.id.textViewTime);
                textViewName = (TextView) itemView.findViewById(R.id.textViewName);
                textViewContext = (TextView) itemView.findViewById(R.id.textViewContext);
                relativeLayoutImage = (RelativeLayout) itemView.findViewById(R.id.relativeLayoutImage);
                imageViewUser = (ImageView) itemView.findViewById(R.id.imageViewUser);
                imageViewContext = (ImageView) itemView.findViewById(R.id.imageViewContext);
            }
            else if(viewType==ITEM_TYPE.File.ordinal()){
                textViewTime = (TextView) itemView.findViewById(R.id.textViewTime);
                imageViewUser = (ImageView) itemView.findViewById(R.id.imageViewUser);
                imageViewFile = (ImageView) itemView.findViewById(R.id.imageViewFile);
                textViewFileName = (TextView) itemView.findViewById(R.id.textViewFileName);
                textViewFileSize = (TextView) itemView.findViewById(R.id.textViewFileSize);
                textViewFileStatus= (TextView) itemView.findViewById(R.id.textViewFileStatus);
                progressBarDownload = (ProgressBar) itemView.findViewById(R.id.progressBarDownload);
                linearLayoutBtn = (LinearLayout) itemView.findViewById(R.id.linearLayoutBtn);
            }
            else if(viewType==ITEM_TYPE.FileOther.ordinal()){
                textViewTime = (TextView) itemView.findViewById(R.id.textViewTime);
                imageViewUser = (ImageView) itemView.findViewById(R.id.imageViewUser);
                textViewName = (TextView) itemView.findViewById(R.id.textViewName);
                imageViewFile = (ImageView) itemView.findViewById(R.id.imageViewFile);
                textViewFileName = (TextView) itemView.findViewById(R.id.textViewFileName);
                textViewFileSize = (TextView) itemView.findViewById(R.id.textViewFileSize);
                textViewFileStatus= (TextView) itemView.findViewById(R.id.textViewFileStatus);
                progressBarDownload = (ProgressBar) itemView.findViewById(R.id.progressBarDownload);
            }
            else if(viewType==ITEM_TYPE.System.ordinal()){
                textViewTime = (TextView) itemView.findViewById(R.id.textViewTime);
                textViewContext = (TextView) itemView.findViewById(R.id.textViewContext);
            }
            else if(viewType==ITEM_TYPE.UploadImg.ordinal()){
                textViewTime = (TextView) itemView.findViewById(R.id.textViewTime);
                textViewContext = (TextView) itemView.findViewById(R.id.textViewContext);
                textViewPercent = (TextView) itemView.findViewById(R.id.textViewPercent);
                relativeLayoutImage = (RelativeLayout) itemView.findViewById(R.id.relativeLayoutImage);
                imageViewContext = (ImageView) itemView.findViewById(R.id.imageViewContext);
                imageViewUser = (ImageView) itemView.findViewById(R.id.imageViewUser);
                linearLayoutPercent = (LinearLayout) itemView.findViewById(R.id.linearLayoutPercent);
                linearLayoutBtn = (LinearLayout) itemView.findViewById(R.id.linearLayoutBtn);
                imgBtnAgin = (ImageButton) itemView.findViewById(R.id.imgBtnAgin);
                progressBar = (ProgressBar) itemView.findViewById(R.id.progressBar);
            }
            else if(viewType==ITEM_TYPE.UploadFile.ordinal()){
                textViewTime = (TextView) itemView.findViewById(R.id.textViewTime);
                imageViewUser = (ImageView) itemView.findViewById(R.id.imageViewUser);
                imageViewFile = (ImageView) itemView.findViewById(R.id.imageViewFile);
                textViewFileName = (TextView) itemView.findViewById(R.id.textViewFileName);
                textViewFileSize = (TextView) itemView.findViewById(R.id.textViewFileSize);
                textViewFileStatus= (TextView) itemView.findViewById(R.id.textViewFileStatus);
                progressBarDownload = (ProgressBar) itemView.findViewById(R.id.progressBarDownload);
                linearLayoutBtn = (LinearLayout) itemView.findViewById(R.id.linearLayoutBtn);
                imgBtnAgin = (ImageButton) itemView.findViewById(R.id.imgBtnAgin);
                progressBar = (ProgressBar) itemView.findViewById(R.id.progressBar);
                linearLayoutContent=(LinearLayout) itemView.findViewById(R.id.linearLayoutContent);
            }
            else{

            }
        }
    }

    public enum ITEM_TYPE {
        None,
        System,
        Text,
        Image,
        File,
        Voice,
        UploadImg,
        UploadFile,
        Download,
        TextOther,
        ImageOther,
        FileOther,
        VoiceOther
    }


}

